#pragma once

#include <memory>
#include "Task.h"


template <typename ResultType>
class CFuture
{

public:
    CFuture(TThreadSafeSharedPtr<CTask<ResultType>> InTask)
    {
        Task=InTask;
    }

    ResultType& Get() const
    {
        Task->PutIntoScheduleIfJustCreated();

        while(true)
        {
            if(Task->IsFinished())
            {
                return Task->GetResult();
            }
        }
    }
protected:
    TThreadSafeSharedPtr<CTask<ResultType>> Task;

};



template <>
class CFuture<void>
{

public:
    CFuture(TThreadSafeSharedPtr<CTask<void>> InTask)
    {
        Task=InTask;
    }

    void Get()
    {
        Task->PutIntoScheduleIfJustCreated();

        while(true)
        {
            if(Task->IsFinished())
            {
                return;
            }
        }
    }
protected:
    TThreadSafeSharedPtr<CTask<void>> Task;

};